cmake_minimum_required(VERSION 3.4)

include_directories(src)

find_file( #find_file will write the XENO_CONFIG to XENO_CONFIG-NOTFOUND if not find the file
	XENO_CONFIG xeno-config
	HINTS /usr/xenomai/bin
	DOC "Xenomai configuration script"
)

if(NOT XENO_CONFIG) #see if(), value that end with -NOTFOUND suffix is considered false
	message(FATAL_ERROR "Xenomai configuration not found in /usr/xenomai/bin")
endif()

execute_process(
	COMMAND ${XENO_CONFIG} --native --rtdm --cflags
	OUTPUT_VARIABLE XENO_CFLAGS
	OUTPUT_STRIP_TRAILING_WHITESPACE
)

execute_process(
	COMMAND ${XENO_CONFIG} --native --rtdm --auto-init-solib --ldflags
	OUTPUT_VARIABLE XENO_LDFLAGS
	OUTPUT_STRIP_TRAILING_WHITESPACE
)


link_directories(/opt/etherlab/lib)
include_directories(/opt/etherlab/include)
add_executable(simple_test src/simple_test.cpp)

target_link_libraries(simple_test ethercat_rtdm)

set_property(
	TARGET simple_test
	APPEND
	PROPERTY LINK_FLAGS ${XENO_LDFLAGS}
)

set_property(
	TARGET simple_test
	APPEND
	PROPERTY COMPILE_FLAGS ${XENO_CFLAGS}
)
